//
//  PassVCScoreViewCell.m
//  LiveSoftware
//
//  Created by lanou3g on 15/7/15.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "PassVCScoreViewCell.h"

#import "PassVCScoreModel.h"

@interface PassVCScoreViewCell ()



/** 日期 */
@property(nonatomic,strong)UILabel*dateLabel;


/** 赛事 */
@property(nonatomic,strong)UILabel*leagueNameLabel;


/** 主队 */
@property(nonatomic,strong)UILabel*homeTeamLabel;



/** 客队 */
@property(nonatomic,strong)UILabel*awayTeamLabel;



/** 比分视图 */
@property(nonatomic,strong)UILabel *scoreLabel;


/** 全场比分 */
@property(nonatomic,strong)UILabel *wholeScore;


/** 半场比分 */
@property(nonatomic,strong)UILabel *halfScore;




@property(nonatomic,copy)NSString *total;
@property(nonatomic,copy)NSString *statistics;
@property(nonatomic,copy)NSString *odds;



@end


@implementation PassVCScoreViewCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        
        
        
        float partHeight = 40;
        //开始高度
        float partY = 0;
        
        CGFloat dataWidth = kScreenIp6(80);
        CGFloat leagueWidth = kScreenIp6(60);
        CGFloat scoreWidth = kScreenIp6(50);
        
        CGFloat partWidth = (kScreenWidth - dataWidth - leagueWidth - scoreWidth - kScreenIp6(10)) / 2;
        
        
        
        //日期
        self.dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, partY, dataWidth, partHeight)];
        self.dateLabel.font = [UIFont systemFontOfSize:12];
        self.dateLabel.textAlignment = NSTextAlignmentCenter;
        self.dateLabel.text = @"日期";
        
        [self addSubview:_dateLabel];
        
        
        //赛事
        self.leagueNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.dateLabel.frame), partY, leagueWidth - kScreenIp6(10), partHeight)];
        self.leagueNameLabel.adjustsFontSizeToFitWidth = YES;
        self.leagueNameLabel.font = [UIFont systemFontOfSize:12];
        self.leagueNameLabel.textAlignment = NSTextAlignmentCenter;
        
        self.leagueNameLabel.text = @"赛事";
        
        [self addSubview:_leagueNameLabel];
        
        
        //主队
        self.homeTeamLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.leagueNameLabel.frame) + kScreenIp6(5), partY, partWidth, partHeight)];
        self.homeTeamLabel.font = [UIFont systemFontOfSize:12];
        self.homeTeamLabel.textAlignment = NSTextAlignmentCenter;
        self.homeTeamLabel.adjustsFontSizeToFitWidth = YES;
        
        self.homeTeamLabel.text = @"主队";
        [self addSubview:_homeTeamLabel];
        
        
        
        //比分视图
        self.scoreLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.homeTeamLabel.frame), partY, scoreWidth, partHeight)];
        self.scoreLabel.font = [UIFont systemFontOfSize:12];
        self.scoreLabel.textAlignment = NSTextAlignmentCenter;
        self.scoreLabel.text = @"";
        
        [self addSubview:_scoreLabel];
        
        // 全场比分
        self.wholeScore = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, scoreWidth, partHeight/2)];
        self.wholeScore.font = [UIFont systemFontOfSize:12];
        self.wholeScore.textAlignment = NSTextAlignmentCenter;
        self.wholeScore.adjustsFontSizeToFitWidth = YES;
        self.wholeScore.text = @"1 : 1";
        
        [self.scoreLabel addSubview:_wholeScore];
        
        
        // 半场比分
        self.halfScore = [[UILabel alloc]initWithFrame:CGRectMake(0, partHeight/2, scoreWidth, partHeight/2)];
        self.halfScore.font = [UIFont systemFontOfSize:11];
        self.halfScore.textAlignment = NSTextAlignmentCenter;
        self.halfScore.adjustsFontSizeToFitWidth = YES;
        self.halfScore.text = @"1 : 0";
        
        [self.scoreLabel addSubview:_halfScore];

        
        
        //客队
        self.awayTeamLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.scoreLabel.frame), partY, partWidth, partHeight)];
        self.awayTeamLabel.font = [UIFont systemFontOfSize:12];
        self.awayTeamLabel.textAlignment = NSTextAlignmentCenter;
        self.awayTeamLabel.adjustsFontSizeToFitWidth = YES;
        self.awayTeamLabel.text = @"客队";
        
        [self addSubview:_awayTeamLabel];
        
        
        
        
        //线
        UIView *footLineView = [[UIView  alloc]initWithFrame:CGRectMake( 0, partHeight, kScreenWidth, 0.5)];
        
        footLineView.backgroundColor = [UIColor colorWithWhite:0.699 alpha:1.000];
        
        [self addSubview:footLineView];
        
        
        
        
        
        // 设置 cell 点击没有变化
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
    }
    
    return self;
    
}



- (void)setCellValueWithModel:(PassVCScoreModel*)model name:(NSString *)name
{
    
    /** 日期 */
    
    NSMutableString *data = [[model.date substringFromIndex:2] mutableCopy];
    [data insertString:@"-" atIndex:2];
    [data insertString:@"-" atIndex:5];
    
    self.dateLabel.text = data;
    
    
    
    /** 赛事 */
    self.leagueNameLabel.text = model.leagueName;
    
    
    /** 主队 */
    self.homeTeamLabel.text = model.homeTeam;
    
    
    /** 客队 */
    self.awayTeamLabel.text = model.awayTeam;
    
    
    /** 全场比分 */
    self.wholeScore.text = [NSString stringWithFormat:@"%@ : %@",model.homeAllScore,model.awayAllScore];
    
    
    /** 半场比分 */
    self.halfScore.text = [NSString stringWithFormat:@"( %@ : %@ )",model.HomeHalfScore,model.awayHalfScore];
    
    
    
    int homeScore = [model.homeAllScore intValue];
    int awayScore = [model.awayAllScore intValue];
    
    // 判定给谁赋颜色
    if ([self.homeTeamLabel.text isEqualToString:name] || [self.homeTeamLabel.text isEqualToString:[NSString stringWithFormat:@"%@(中)",name]]) // 主队为主
    {
        
        
        if (homeScore == awayScore) // 平
        {
            self.homeTeamLabel.textColor = [UIColor colorWithRed:0.147 green:0.277 blue:1.000 alpha:1.000];
        }
        else if (homeScore < awayScore) // 负
        {
             self.homeTeamLabel.textColor = [UIColor colorWithRed:0.304 green:0.734 blue:0.177 alpha:1.000];
        }
        else // 胜
        {
            self.homeTeamLabel.textColor = [UIColor redColor];
        }
        
        
    }
    else // 客队为主
    {
        
        if (homeScore == awayScore) // 平
        {
            self.awayTeamLabel.textColor = [UIColor colorWithRed:0.147 green:0.277 blue:1.000 alpha:1.000];
        }
        else if (homeScore < awayScore) // 胜
        {
            self.awayTeamLabel.textColor = [UIColor redColor];
        }
        else //负
        {
            self.awayTeamLabel.textColor = [UIColor colorWithRed:0.304 green:0.734 blue:0.177 alpha:1.000];
        }
        
        
    }
    
    
    
}




/*
 else // 客队为主
 {
 static int awayWin;
 static int awayDraw;
 static int awayLoss;
 
 if (homeScore == awayScore) // 平
 {
 self.awayTeamLabel.textColor = [UIColor colorWithRed:0.147 green:0.277 blue:1.000 alpha:1.000];
 awayDraw++;
 }
 else if (homeScore < awayScore) // 胜
 {
 self.awayTeamLabel.textColor = [UIColor redColor];
 awayWin++;
 }
 else //负
 {
 self.awayTeamLabel.textColor = [UIColor colorWithRed:0.304 green:0.734 blue:0.177 alpha:1.000];
 awayLoss++;
 }
 
 self.total = [NSString stringWithFormat:@"共%d场",(awayWin + awayDraw + awayLoss)];
 self.statistics = [NSString stringWithFormat:@"%d胜%d平%d负",awayWin,awayDraw,awayLoss];
 self.odds = [NSString stringWithFormat:@"胜率%d%%",awayWin/(awayWin + awayDraw + awayLoss)*100];
 
 NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:self.total,@"total",self.statistics,@"statistics",self.odds,@"odds", nil];
 
 [[NSNotificationCenter defaultCenter] postNotificationName:@"totalViewAssignMent" object:nil userInfo:dic];
 
 }
 */



@end
